package com.itheima.thread12;

import java.util.concurrent.locks.ReentrantLock;

public class MyThread extends Thread {
    private int count = 1000;
    private Object obj = new Object();
    private ReentrantLock rtl = new ReentrantLock();

    @Override
    public void run() {
        while (true) {

            //synchronized (obj) {
            try {
                rtl.lock();
                if (count == 0) {
                    break;
                } else {
                        Thread.sleep(100);
                    count--;
                    System.out.println(Thread.currentThread().getName() + "正在买票,还剩" + count + "张票");
                //}
            }

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                rtl.unlock();
            }
        }
    }
}














